package com.example.zhyq.fg

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.mvvm.BaseFragment
import com.example.zhyq.R
import com.example.zhyq.adapter.AnnouncementAdapter
import com.example.zhyq.databinding.FragmentHomeBinding
import com.example.zhyq.fgViewModel.HomeViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding,HomeViewModel>() {

    lateinit var announcementAdapter: AnnouncementAdapter
    override fun initView() {
        vm.getAnnouncement(0,10)
        announcementAdapter = AnnouncementAdapter()
        binding.rvNotice.adapter=announcementAdapter
        binding.rvNotice.layoutManager = LinearLayoutManager(requireContext())

        binding.llPark.setOnClickListener {
            ARouter.getInstance().build("/app/ParkActivity").navigation()
        }

        binding.llSign.setOnClickListener {
            ARouter.getInstance().build("/app/SignActivity").navigation()
        }

        binding.llDevice.setOnClickListener {
            ARouter.getInstance().build("/app/EmpActivity").navigation()
        }

        binding.llHouse.setOnClickListener {
            ARouter.getInstance().build("/app/HouseActivity").navigation()
        }

        binding.llShop.setOnClickListener {
            ARouter.getInstance().build("/app/MerchantActivity").navigation()
        }
    }

    override fun initData() {
        vm.getAnnouncementSuc.observe(this){
            announcementAdapter.data.clear()
            announcementAdapter.data.addAll(it)
            announcementAdapter.notifyDataSetChanged()
        }
    }

}